<?php

##################################################
#
# Copyright (c) 2004-2006 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################

/**
* Change logs
* Sep 12, 2011 - trungdt - Add seo_name
* Nov 9, 2011 - trungdt - Add cat_value
*/

class payment {
	function form($card_user) {
		global $db;
            //Form 
    $i18n = exponent_lang_loadFile('subsystems/users/profileextensions/billingformextension.php');
         $form = new form();
         $form->meta('uid',$card_user->uid);
        //$form->register(null, "", new htmlcontrol('<hr/><b>' . $i18n['header'] . '</b>'));
        //Card type - sonhb
       // $card_user=$db->selectObject('user_billingform',"uid=" . $user->id); 
        if(!isset($card_user->cardtype)){
          $card_default=$db->selectObject('billing_cc_type','`default`=1')   ;
        }
        else
        {
           $card_default->id=  $card_user->cardtype;
        } 
         $cardtype=$db->selectDropdown('billing_cc_type','name');
              
        $form->register('cardtype',$i18n['cardtype'],new dropdowncontrol($card_default->id,$cardtype,false));
        $form->register("name_on_card", $i18n["name_on_card"], new textcontrol($card_user->name_on_card, 16, false, 15));
        $form->register("card_num", $i18n["card_num"], new textcontrol($card_user->card_num, 16, false, 15));
        //Expiration Date  
        //Moth
        for($d=1;$d<=12;$d++)
        {
            $month[$d]=$d;
        }
         $form->register('month_exp',$i18n['month_exp'],new dropdowncontrol($card_user->month_exp,$month,false));

        //Year
       
        for($d=2012;$d<=2030;$d++)
        {
            $year[$d]=$d;
        }
          $form->register('year_exp',$i18n['year_exp'],new dropdowncontrol($card_user->year_exp,$year,false));

        
        $form->register("secur_code", $i18n["secur_code"], new textcontrol($card_user->secur_code, 10, false, 15));
        $form->register('submit','',new buttongroupcontrol($i18n['save'],'',$i18n['cancel']));
    //-------------
        $form->register("name_on_card", $i18n["name_on_card"], new textcontrol($card_user->name_on_card, 16, false, 15));
        $form->register("card_num", $i18n["card_num"], new textcontrol($card_user->card_num, 16, false, 15));

        
        
		return $form;
	}
	
	function update($values,$object) {
		$object->name = $values['name'];
		$object->cat_value = $values['cat_value'];
		$object->color = "#".$values['color'];
		if (trim($values['seo_name']) == '')
		{
			$object->seo_name=_to_vietnamese_with_nomark(_ab_safe_html_string($object->name));
		}
		else
		{
			$object->seo_name=_to_vietnamese_with_nomark(_ab_safe_html_string(trim($values['seo_name'])));
		}
		return $object;
	}
}

?>
